package com.tiyo.monitor.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tiyo.common.annotation.Log;
import com.tiyo.common.core.domain.AjaxResult;
import com.tiyo.common.enums.BusinessType;
import com.tiyo.framework.shiro.service.PasswordService;
import com.tiyo.framework.web.controller.BaseController;
import com.tiyo.monitor.mapper.domain.SysLoginLog;
import com.tiyo.monitor.service.SysLoginLogService;
/**
 * 
 * @Description 登录日志管理
 * @author yangb
 * @version v1.0
 * @date 2021年1月21日
*
 */
@RequestMapping("/monitor/loginlog")
@Controller
public class SysLoginLogController extends BaseController {
	 private String prefix = "monitor/loginlog";

	    @Autowired
	    private SysLoginLogService sysLoginLogService;

	    @Autowired
	    private PasswordService passwordService;

	    @RequiresPermissions("monitor:logininfor:view")
	    @GetMapping()
	    public String loginlog()
	    {
	        return prefix + "/loginlog";
	    }

	    @RequiresPermissions("monitor:logininfor:list")
	    @PostMapping("/list")
	    @ResponseBody
	    public AjaxResult list(SysLoginLog logininfor)
	    {
	    	IPage<SysLoginLog> page = sysLoginLogService.selectLogininforList(logininfor);
	    	 return AjaxResult.success(page);
	    }

	    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
	    @RequiresPermissions("monitor:logininfor:export")
	    @PostMapping("/export")
	    @ResponseBody
	    public AjaxResult export(SysLoginLog logininfor)
	    {
	        return AjaxResult.success();
	    }

	    @RequiresPermissions("monitor:logininfor:remove")
	    @Log(title = "登录日志", businessType = BusinessType.DELETE)
	    @PostMapping("/remove")
	    @ResponseBody
	    public AjaxResult remove(String ids)
	    {
	    	sysLoginLogService.deleteLogininforByIds(ids);
	        return AjaxResult.success();
	    }

	    @RequiresPermissions("monitor:logininfor:remove")
	    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
	    @PostMapping("/clean")
	    @ResponseBody
	    public AjaxResult clean()
	    {
	    	sysLoginLogService.cleanLogininfor();
	        return success();
	    }

	    @RequiresPermissions("monitor:logininfor:unlock")
	    @Log(title = "账户解锁", businessType = BusinessType.OTHER)
	    @PostMapping("/unlock")
	    @ResponseBody
	    public AjaxResult unlock(String loginName)
	    {
	        passwordService.clearLoginRecordCache(loginName);
	        return success();
	    }
}
